home *** CD-ROM | disk | FTP | other *** search
/ Amiga Collections: Camelot / Camelot 043 (1989-06)(Swedish User Group of Amiga)(SE)(PD)[WB].zip / Camelot 043 (1989-06)(Swedish User Group of Amiga)(SE)(PD)[WB].adf / Glib / st-mach.c < prev    next >
C/C++ Source or Header  |  1989-03-16  |  6KB  |  374 lines

  1. /*
  2.  * GLIB - a Generic LIBrarian and editor for synths
  3.  *
  4.  * Machine dependent stuff.
  5.  */
  6.  
  7. #include "glib.h"
  8. #include <ctype.h>
  9.  
  10. int Rows, Cols;
  11.  
  12. #define EscSeq(x) Cconout('\033');Cconout(x);
  13. struct iorecinfo {
  14.     char *ibuf;
  15.     int ibufsiz;
  16.     int ibufhd;
  17.     int ibuftl;
  18.     int ibuflow;
  19.     int ibufhigh;
  20. };
  21. #define MIDIBUFSIZE 5000
  22. char *Origbuf;
  23. int Origsize;
  24. struct iorecinfo *Ioptr;
  25. int work_in[12], work_out[60];  /* GEM & VDI stuff */
  26. int intin[128], ptsin[128];
  27. int intout[128], ptsout[128];
  28. int contrl[12];
  29. int Handle, Vhandle;
  30.  
  31. /* These contain the raw voice data */
  32. hello()
  33. {
  34.     int dummy, n;
  35.  
  36.     appl_init();
  37.  
  38.     /* Get the Midi Iorec and put in a bigger buffer */
  39.     flushmidi();
  40.     Ioptr = (struct iorecinfo *)(Iorec(2));
  41.     Origbuf = Ioptr->ibuf;
  42.     Origsize = Ioptr->ibufsiz;
  43.     Ioptr->ibuf = alloc(MIDIBUFSIZ);
  44.     Ioptr->ibufsiz = MIDIBUFSIZ;
  45.     Ioptr->ibuftl = Ioptr->ibufhd = 0;
  46.     Cursconf(2,0);        /* set non-blinking block cursor */
  47.     mouseon();
  48. }
  49.  
  50. bye()
  51. {
  52.     /* Restore the original Midi Iorec buffer */
  53.     flushmidi();
  54.     Ioptr->ibuf = Origbuf;
  55.     Ioptr->ibufsiz = Origsize;
  56.     Ioptr->ibuftl = Ioptr->ibufhd = 0;
  57.     mouseoff();
  58.     appl_exit();
  59.  
  60.     /* are these ever called? SAF */
  61.     windgoto(23,0);
  62.     windrefresh();
  63.     windexit(0);
  64. }
  65.  
  66. /* getmouse - get currect row and column of mouse */
  67. getmouse(amr,amc)
  68. int *amr;
  69. int *amc;
  70. {
  71. #ifdef USEMOUSE
  72.     int button, ret, keycode, tmp1, tmp2;
  73.     char msgbuf[8];
  74.  
  75.     graf_mkstate(amc,amr,&tmp1,&tmp2);
  76.     /* evnt_multi(MU_TIMER,
  77.         0,0,0,
  78.         0,0,0,0,0,
  79.         0,0,0,0,0,
  80.         msgbuf, 0, 0,
  81.         amc, amr, &button, &ret, &keycode, &ret); */
  82.     /* convert bitmap x,y coordinates to row,colum */
  83.     *amr = (*amr)/16;
  84.     *amc = (*amc)/8;
  85. #else
  86.     *amr = -1;
  87.     *amc = -1;
  88. #endif
  89. }
  90.  
  91. /* statmouse - return mouse button state (0=nothing pressed,1=left,2=right) */
  92. statmouse()
  93. {
  94. #ifdef USEMOUSE
  95.     int tmp1, tmp2, tmp3, buttons;
  96.     char msgbuf[8];
  97.  
  98.     graf_mkstate(&tmp1,&tmp2,&buttons,&tmp3);
  99.     /* evnt_multi(MU_TIMER,
  100.         0,0,0,
  101.         0,0,0,0,0,
  102.         0,0,0,0,0,
  103.         msgbuf, 0, 0,
  104.         &tmp1, &tmp1, &buttons, &tmp1, &tmp1, &tmp1); */
  105.     return(buttons);
  106. #else
  107.     return(-1);
  108. #endif
  109. }
  110.  
  111. int Mouseshown = 0;
  112. mouseon()
  113. {
  114. #ifdef USEMOUSE
  115.     if ( Mouseshown == 0 ) {
  116.         Vsync();    /* wait until next VBI to ensure updating */
  117.         Cursconf(1,0);        /* show block cursor */
  118.         Vsync();    /* wait until next VBI to ensure updating */
  119.         graf_mouse(257,NULL);    /* display mouse cursor */
  120.         Mouseshown = 1;
  121.         Vsync();
  122.     }
  123. #endif
  124. }
  125. mouseoff()
  126. {
  127. #ifdef USEMOUSE
  128.     if ( Mouseshown == 1 ) {
  129.         Vsync();    /* wait until next VBI to ensure updating */
  130.         graf_mouse(256,NULL);    /* hide mouse cursor */
  131.         Vsync();    /* wait until next VBI to ensure updating */
  132.         Cursconf(0,0);        /* hide block cursor */
  133.         Mouseshown = 0;
  134.         Vsync();
  135.     }
  136. #endif
  137. }
  138.  
  139. /* Return when either a console key or mouse button is pressed. */
  140. mouseorkey()
  141. {
  142. #ifdef USEMOUSE
  143.     int evnt, ret, keycode, button, mx, my, tmp1, tmp2, tmp3;
  144.     char msgbuf[8];
  145.  
  146.     mouseon();
  147.     for ( ;; ) {
  148.         graf_mkstate(&tmp1,&tmp2,&button,&tmp3);
  149.         /* evnt = evnt_multi(MU_TIMER,
  150.             0,0,0,
  151.             0,0,0,0,0,
  152.             0,0,0,0,0,
  153.             msgbuf, 0, 0,
  154.             &mx, &my, &button, &ret, &keycode, &ret); */
  155.         if ( button != 0 ) {
  156.             return(MOUSE);
  157.         }
  158.         if ( statmouse() > 0 )
  159.             return(MOUSE);
  160.         if ( statconsole() )
  161.             return(getconsole());
  162.     }
  163. #else
  164.     return(getconsole());
  165. #endif
  166. }
  167.  
  168. flushconsole()
  169. {
  170.     while ( statconsole() )
  171.         getconsole();
  172. }
  173.  
  174. statconsole()
  175. {
  176.     /* return(Bconstat(CONSOLE)); */
  177.     return(Cconis());
  178. }
  179.  
  180. getconsole()
  181. {
  182.     /* return(Bconin(CONSOLE)); */
  183.     return(Crawcin());
  184. }
  185.  
  186. getmidi()
  187. {
  188.     return(Bconin(MIDI));
  189. }
  190.  
  191. /*ARGSUSED*/
  192. sendmidi(c)
  193. {
  194.     Bconout(MIDI,c);
  195. }
  196.  
  197. flushmidi()
  198. {
  199.     while ( STATMIDI )
  200.         getmidi();
  201. }
  202.  
  203. long milliclock()
  204. {
  205.     register long save_ssp=Super(0L);
  206.     register long uhz200= *(long *)0x4ba;
  207.     Super(save_ssp);
  208.     return(uhz200 * 5);
  209. }
  210.  
  211. millisleep(n)
  212. {
  213.     long first = milliclock();
  214.     while ( milliclock() < (first+n) )
  215.         ;
  216. }
  217.  
  218. char *
  219. alloc(n)
  220. {
  221.     char *p;
  222.  
  223.     if ( (p=malloc((unsigned)n)) == (char *)NULL ) {
  224.         printf("*** Whoops *** alloc has failed?!?  No more memory!\n");
  225.         fflush(stdout);
  226.         bye();
  227.     }
  228.     return(p);
  229. }
  230.  
  231. windinit()
  232. {
  233.     Cols=80;
  234.     Rows=25;
  235.     Cursconf(1,NULL);
  236. }
  237.  
  238. windgoto(r,c)
  239. int r,c;
  240. {
  241.     mouseoff();
  242.     EscSeq('Y');
  243.     Cconout(r+040);
  244.     Cconout(c+040);
  245. }
  246.  
  247. windeeol()
  248. {
  249.     mouseoff();
  250.     EscSeq('K');
  251. }
  252.  
  253. winderaserow(r)
  254. {
  255.     windgoto(r,0);
  256.     windeeol();
  257. }
  258.  
  259. windexit(r)
  260. int r;
  261. {
  262.     exit(r);
  263. }
  264.  
  265. windclear()
  266. {
  267.     mouseoff();
  268.     EscSeq('H');
  269.     EscSeq('J');
  270. }
  271.  
  272. /* windgets - get a line of input from the console, handling backspaces */
  273. windgets(s)
  274. char *s;
  275. {
  276.     char *origs = s;
  277.     int c;
  278.  
  279.     while ( (c=getconsole()) != '\n' && c!='\r' && c!= EOF ) {
  280.         if ( c == '\b' ) {
  281.             if ( s > origs ) {
  282.                 windstr("\b \b");
  283.                 s--;
  284.             }
  285.         }
  286.         else {
  287.             windputc(c);
  288.             *s++ = c;
  289.         }
  290.         windrefresh();
  291.     }
  292.     *s = '\0';
  293. }
  294.  
  295. windstr(s)
  296. char *s;
  297. {
  298.     int c;
  299.  
  300.     while ( (c=(*s++)) != '\0' )
  301.         windputc(c);
  302. }
  303.  
  304. windputc(c)
  305. int c;
  306. {
  307.     mouseoff();
  308.     Cconout(c);
  309. }
  310.  
  311. windrefresh()
  312. {
  313. }
  314.  
  315. beep()
  316. {
  317.     Cconout('\007');
  318. }
  319.  
  320. windhigh()
  321. {
  322. }
  323.  
  324. windnorm()
  325. {
  326. }
  327.  
  328. /****************
  329.  * openls(), nextls(), and closels() are used to scan the current directory.
  330.  ***************/
  331.  
  332. char Dtabuff[44];
  333. long Origdta;
  334. int Atarifirst = 0;
  335.  
  336. char *
  337. openls()
  338. {
  339.     int n, c;
  340.  
  341.     Origdta = Fgetdta();
  342.     Fsetdta(Dtabuff);
  343.     Atarifirst = 1;
  344. }
  345. char *
  346. nextls()
  347. {
  348.     static char fname[17];
  349.     int n, c;
  350.  
  351.     if ( Atarifirst ) {
  352.         if ( Fsfirst("*.*",0x10) < 0 )
  353.             return(NULL);
  354.     }
  355.     else {
  356.         if ( Fsnext() < 0 )
  357.             return(NULL);
  358.     }
  359.     Atarifirst = 0;
  360.     for ( n=0; n<14; n++ ) {
  361.         c = fname[n] = Dtabuff[30+n];
  362.         /* ALL phrase names are lower case */
  363.         if ( c >= 'A' && c <= 'Z' )
  364.             fname[n] = c - 'A' + 'a';
  365.     }
  366.     fname[14] = '\0';
  367.     return(fname);
  368. }
  369. closels()
  370. {
  371.     Fsetdta((char *)Origdta);
  372. }
  373.  
  374.